package com.ruoyi.system.service.impl;

import java.text.SimpleDateFormat;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.TBOrderDeviceMapper;
import com.ruoyi.system.domain.TBOrderDevice;
import com.ruoyi.system.service.ITBOrderDeviceService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 订单关联设备Service业务层处理
 * 
 * @author pspyy
 * @date 2022-03-09
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class TBOrderDeviceServiceImpl implements ITBOrderDeviceService 
{
    @Autowired
    private TBOrderDeviceMapper tBOrderDeviceMapper;

    /**
     * 查询订单关联设备
     * 
     * @param id 订单关联设备主键
     * @return 订单关联设备
     */
    @Override
    public TBOrderDevice selectTBOrderDeviceById(Long id)
    {
        return tBOrderDeviceMapper.selectTBOrderDeviceById(id);
    }

    @Override
    public TBOrderDevice selectTBOrderDeviceByCode(String code) {
        return tBOrderDeviceMapper.selectTBOrderDeviceByCode(code);
    }

    /**
     * 查询订单关联设备列表
     * 
     * @param tBOrderDevice 订单关联设备
     * @return 订单关联设备
     */
    @Override
    public List<TBOrderDevice> selectTBOrderDeviceList(TBOrderDevice tBOrderDevice)
    {
        return tBOrderDeviceMapper.selectTBOrderDeviceList(tBOrderDevice);
    }

    /**
     * 新增订单关联设备
     * 
     * @param tBOrderDevice 订单关联设备
     * @return 结果
     */
    @Override
    public int insertTBOrderDevice(TBOrderDevice tBOrderDevice)
    {
        tBOrderDevice.setCreateTime(DateUtils.getNowDate());
        return tBOrderDeviceMapper.insertTBOrderDevice(tBOrderDevice);
    }

    /**
     * 修改订单关联设备
     * 
     * @param tBOrderDevice 订单关联设备
     * @return 结果
     */
    @Override
    public int updateTBOrderDevice(TBOrderDevice tBOrderDevice)
    {
        tBOrderDevice.setUpdateTime(DateUtils.getNowDate());
        return tBOrderDeviceMapper.updateTBOrderDevice(tBOrderDevice);
    }

    /**
     * 批量删除订单关联设备
     * 
     * @param ids 需要删除的订单关联设备主键
     * @return 结果
     */
    @Override
    public int deleteTBOrderDeviceByIds(Long[] ids)
    {
        return tBOrderDeviceMapper.deleteTBOrderDeviceByIds(ids);
    }

    /**
     * 删除订单关联设备信息
     * 
     * @param id 订单关联设备主键
     * @return 结果
     */
    @Override
    public int deleteTBOrderDeviceById(Long id)
    {
        return tBOrderDeviceMapper.deleteTBOrderDeviceById(id);
    }

    @Override
    public int deleteByNoAndDevId(String no, Long devId) {
        return tBOrderDeviceMapper.deleteByNoAndDevId(no,devId);
    }

    @Override
    public List<Long> selectDeviceIdList(String orderNum) {
        return tBOrderDeviceMapper.selectDeviceIdList(orderNum);
    }

    @Override
    public int deleteTBOrderDeviceByOrderNum(String orderNum) {
        return tBOrderDeviceMapper.deleteTBOrderDeviceByOrderNum(orderNum);
    }

    @Override
    public int unLockDevice(Long[] ids) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        for (Long id:ids) {
            TBOrderDevice orderDevice = new TBOrderDevice();
            orderDevice.setDeviceStatue("3");
            orderDevice.setLockTime(sdf.format(DateUtils.getNowDate()));
            orderDevice.setUpdateTime(DateUtils.getNowDate());
        }
        return tBOrderDeviceMapper.unLockDevice(ids);
    }

    @Override
    public int lockDevice(Long[] ids) {
        return tBOrderDeviceMapper.lockDevice(ids);
    }

    @Override
    public List<TBOrderDevice> selectByDeviceId(Long[] ids) {
        return tBOrderDeviceMapper.selectByDeviceId(ids);
    }

    @Override
    public Long selectByOrderNum(String orderNum) {
        return tBOrderDeviceMapper.selectByOrderNum(orderNum);
    }

    @Override
    public List<String> validateStatus(String orderNum) {
        return tBOrderDeviceMapper.validateStatus(orderNum);
    }


}
